﻿CREATE PROCEDURE [maint].[GetStatsLatency]
@DbName [sysname], @Latency INT OUTPUT, @OutputDiagnostics BIT=0
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @RC int, @ERROR int
	SET @RC = 0

	IF(@OutputDiagnostics = 1)
		BEGIN
			PRINT OBJECT_NAME(@@PROCID)
			PRINT N'	@DbName = N''' + ISNULL(@DbName,N'NULL') + ''''
		END

	SELECT
		@Latency = [StatsLatency]
	FROM [config].[DbMaintenance]
	WHERE ([DbName] = @DbName)

	IF(@@ROWCOUNT = 0)
	BEGIN
		RAISERROR('Database [%s] does not have any configuration data.',16,1,@DbName)
		SET @RC = @@ERROR
	END

EXIT_PROC:
	RETURN(@RC)
END